/**
 * Sample plugin.
 */
Draw.loadPlugin(function (ui) {
	var graph = ui.editor.graph;

	function updateOverlays(cell) {
		var tooltip = cell.getAttribute("tooltip");

		if (tooltip != null && tooltip.length > 0) {
			var overlays = graph.getCellOverlays(cell);

			if (overlays == null) {
				// Creates a new overlay with an image
				var overlay = new mxCellOverlay(
					new mxImage(
						"",
						62,
						62
					),
					null,
					mxConstants.ALIGN_RIGHT,
					mxConstants.ALIGN_TOP,
					null,
					"default"
				);

				// Sets the overlay for the cell in the graph
				graph.addCellOverlay(cell, overlay);
			}
		} else {
			graph.removeCellOverlays(cell);
		}
	}

	function refresh() {
		var cells = graph.model.cells;

		for (var id in cells) {
			updateOverlays(cells[id]);
		}
	}

	graph.addListener(mxEvent.SIZE, refresh);
	refresh();
});
